package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.Casefields;
import com.g8.pethospitallearnbackend.exception.CustomException;
import com.g8.pethospitallearnbackend.service.CasefieldsService;
import com.g8.pethospitallearnbackend.utils.responseUtil.ResponseStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("")
public class CasefieldsController {
    @Autowired
    private CasefieldsService casefieldsService;
    /**
     * 修改病例字段
     * 在同一个RequestMapping下不同的PostMapping会有冲突哦
     * @param modifiedFields
     * @return
     */
    @PostMapping("/casefield/modify")
    public List<String> modifyCasefield(@RequestBody List<Casefields> modifiedFields){
        log.info("获取参数"+modifiedFields.size());
        List<String> modifiedEnFields=casefieldsService.modifyCasefieldByEnAttr(modifiedFields);
        if(modifiedEnFields==null||modifiedEnFields.isEmpty())
            throw new CustomException(ResponseStatusEnum.DATA_NOT_EXIST,"修改数据0条");
        return modifiedEnFields;
    }

    @PostMapping("/casefield/add/{chAttr}")
    public String addCasefield(@PathVariable String chAttr){
        return casefieldsService.addCasefield(chAttr);
    }

    @DeleteMapping("casefield/delete/{chAttr}")
    public String deleteCasefield(@PathVariable String chAttr){
        return casefieldsService.deleteCasefield(chAttr);
    }

    @GetMapping("casefield/en")
    public List<String> getEnFields(){
        List<String> enFields=casefieldsService.getEnFields();
        if(enFields==null||enFields.isEmpty()) throw new CustomException(ResponseStatusEnum.DATA_NOT_EXIST,"病例模板不存在字段");
        return enFields;
    }
}
